package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.QgPayRechargeDetail;
import com.ruoyi.web.dto.QgPayRechargeDetailAddDTO;
import com.ruoyi.web.service.IQgPayRechargeDetailService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * QGPay充值明细Controller
 *
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/qg-pay/recharge-detail")
@AllArgsConstructor
public class QgPayRechargeDetailController extends BaseController {
    private IQgPayRechargeDetailService qgPayRechargeDetailService;

    /**
     * 查询QGPay充值明细列表
     */
    @PreAuthorize("@ss.hasPermi('qgPay:rechargeDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(QgPayRechargeDetail qgPayRechargeDetail) {
        startPage();
        List<QgPayRechargeDetail> list = qgPayRechargeDetailService.selectQgPayRechargeDetailList(qgPayRechargeDetail);
        return getDataTable(list);
    }

    /**
     * 导出QGPay充值明细列表
     */
    @PreAuthorize("@ss.hasPermi('qgPay:rechargeDetail:export')")
    @Log(title = "QGPay充值明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QgPayRechargeDetail qgPayRechargeDetail) {
        List<QgPayRechargeDetail> list = qgPayRechargeDetailService.selectQgPayRechargeDetailList(qgPayRechargeDetail);
        ExcelUtil<QgPayRechargeDetail> util = new ExcelUtil<QgPayRechargeDetail>(QgPayRechargeDetail.class);
        util.exportExcel(response, list, "QGPay充值明细数据");
    }

    /**
     * 获取QGPay充值明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('qgPay:rechargeDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qgPayRechargeDetailService.selectQgPayRechargeDetailById(id));
    }

    /**
     * 创建支付
     *
     * @param dto dto
     * @return {@link AjaxResult}
     * @since 2023/3/15 17:32
     */
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody @Validated QgPayRechargeDetailAddDTO dto) {
        String url = qgPayRechargeDetailService.add(dto);
        return success((Object) url);
    }

    /**
     * h5分页查询
     *
     * @param condition 查询条件
     * @return {@link TableDataInfo}
     * @since 2023/3/17 10:51
     */
    @GetMapping("/app/page")
    public TableDataInfo appPage(QgPayRechargeDetail condition) {
        startPage();
        List<QgPayRechargeDetail> list = qgPayRechargeDetailService.appPage(condition);
        return getDataTable(list);
    }
}
